<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  users
 */

class m_users_actions_block_GroupsEditAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$documentId = $this->getRequestParameter("docId");
		$tabName = $this->getRequestParameter("tabName");
		$tabbed = $this->getRequestParameter("tabbed");
		
		$group = f_document_Provider::getInstance()->getByModelAndUniqueId('users/Group', $documentId);
		
        $formProvider = f_form_Provider::getInstance();

        $formProvider->setDocumentName("groups")
                     ->setModuleName("users")
                     ->setFormName("FormGroups");

        $values = $formProvider->getParams();
        if($this->getUserContext()->hasRight("users_Edit"))
        {
            if($formProvider->isSubmitted())
            {
                if($formProvider->isValid())
                {
                    $group
                        ->setAuthor($this->getUser()->getLogin())
                        ->setLabel($values['formValues']['label'])
                        ->save();
                }
                else
                {
                    $values['errors'] = $formProvider->getErrors();
                    $values['errors']['status'] = "failed";
                }
            }
        }

		$values["group"] = $group;
		$values["tabName"] = $tabName;
		$values["tabbed"] = $tabbed;

		$this->setModel($values);
		$this->setView('success');
	}	
}